"""add decision_presets table"""

from alembic import op
import sqlalchemy as sa


revision = "202510200001"
down_revision = "202510190002"
branch_labels = None
depends_on = None


def upgrade() -> None:
  op.create_table(
    "decision_presets",
    sa.Column("id", sa.Integer(), primary_key=True, index=True),
    sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
    sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
    sa.Column("deleted_at", sa.DateTime(timezone=True), nullable=True),
    sa.Column("user_id", sa.Integer(), nullable=False, index=True),
    sa.Column("relationship_id", sa.Integer(), nullable=True, index=True),
    sa.Column("title", sa.String(length=180), nullable=False),
    sa.Column("options_json", sa.JSON(), nullable=False),
    sa.Column("style", sa.String(length=32), nullable=False, server_default="wheel"),
    sa.Column("is_shared", sa.Boolean(), nullable=False, server_default=sa.text("false")),
    sa.Column("color_seed", sa.String(length=32), nullable=True),
    sa.Column("usage_count", sa.Integer(), nullable=False, server_default="0"),
    sa.Column("last_used_at", sa.DateTime(timezone=True), nullable=True),
    sa.Column("last_result", sa.String(length=180), nullable=True),
    sa.ForeignKeyConstraint(["relationship_id"], ["relationships.id"], ondelete="SET NULL"),
    sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
  )


def downgrade() -> None:
  op.drop_table("decision_presets")
